package com.gitee.wsl.struct.attribute.pairs


/** Stores single [Parameter] value, its name, unified ID and weights needed for AllPairs algorithm.  */
class Item(val itemId: String, val value: Any, val name: String) : Comparable<Item> {

    var weights: List<Int> = ArrayList()

    override operator fun compareTo(other: Item): Int {
        return INTEGER_LIST_LEXICOGRAPHICAL_COMPARATOR.compare(
            weights,
            other.weights
        )
    }

    companion object {
        private val INTEGER_LIST_LEXICOGRAPHICAL_COMPARATOR =
            Comparator { o1: List<Int>, o2: List<Int> ->
                val i1 = o1.iterator()
                val i2 = o2.iterator()
                var result: Int
                do {
                    if (!i1.hasNext()) {
                        return@Comparator if (!i2.hasNext()) 0 else -1
                    }
                    if (!i2.hasNext()) {
                        return@Comparator 1
                    }
                    result = i1.next().compareTo(i2.next())
                } while (result == 0)
                result
            }
    }
}

